home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / out-of-phase-102-c / OutOfPhase 1.02 Source / OutOfPhase Folder / LFOSpecifier.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  5.9 KB  |  199 lines  |  [TEXT/KAHL]

  1. /* LFOSpecifier.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "LFOSpecifier.h"
  31. #include "Memory.h"
  32. #include "Envelope.h"
  33. #include "SampleSelector.h"
  34.  
  35.  
  36. struct LFOSpecRec
  37.     {
  38.         /* envelope that determines the frequency of the LFO oscillator */
  39.         EnvelopeRec*                    FrequencyEnvelope;
  40.  
  41.         /* envelope that determines the amplitude of the LFO wave */
  42.         EnvelopeRec*                    AmplitudeEnvelope;
  43.  
  44.         /* envelope that determines wave table index -- wave table LFOs only */
  45.         EnvelopeRec*                    WaveTableIndexEnvelope;
  46.  
  47.         /* sample / wave table sources */
  48.         SampleSelectorRec*        SampleSources;
  49.  
  50.         /* what kind of wave generator should we use */
  51.         LFOOscTypes                        Oscillator;
  52.  
  53.         /* how should the LFO wave affect the stream being modulated */
  54.         LFOModulationTypes        ModulationMode;
  55.  
  56.         /* how are the signals combined */
  57.         LFOAdderMode                    AddingMode;
  58.     };
  59.  
  60.  
  61. /* create a new LFO specification record */
  62. LFOSpecRec*                        NewLFOSpecifier(void)
  63.     {
  64.         LFOSpecRec*                    LFOSpec;
  65.  
  66.         LFOSpec = (LFOSpecRec*)AllocPtrCanFail(sizeof(LFOSpecRec),"LFOSpecRec");
  67.         if (LFOSpec == NIL)
  68.             {
  69.              FailurePoint1:
  70.                 return NIL;
  71.             }
  72.         LFOSpec->FrequencyEnvelope = NewEnvelope();
  73.         if (LFOSpec->FrequencyEnvelope == NIL)
  74.             {
  75.              FailurePoint2:
  76.                 ReleasePtr((char*)LFOSpec);
  77.                 goto FailurePoint1;
  78.             }
  79.         LFOSpec->AmplitudeEnvelope = NewEnvelope();
  80.         if (LFOSpec->AmplitudeEnvelope == NIL)
  81.             {
  82.              FailurePoint3:
  83.                 DisposeEnvelope(LFOSpec->FrequencyEnvelope);
  84.                 goto FailurePoint2;
  85.             }
  86.         LFOSpec->WaveTableIndexEnvelope = NewEnvelope();
  87.         if (LFOSpec->WaveTableIndexEnvelope == NIL)
  88.             {
  89.              FailurePoint4:
  90.                 DisposeEnvelope(LFOSpec->AmplitudeEnvelope);
  91.                 goto FailurePoint3;
  92.             }
  93.         LFOSpec->SampleSources = NewSampleSelectorList(0);
  94.         if (LFOSpec->SampleSources == NIL)
  95.             {
  96.              FailurePoint5:
  97.                 DisposeEnvelope(LFOSpec->WaveTableIndexEnvelope);
  98.                 goto FailurePoint4;
  99.             }
  100.         LFOSpec->Oscillator = eLFOSignedSine;
  101.         LFOSpec->ModulationMode = eLFOAdditive;
  102.         LFOSpec->AddingMode = eLFOArithmetic;
  103.         return LFOSpec;
  104.     }
  105.  
  106.  
  107. /* dispose an LFO specification */
  108. void                                    DisposeLFOSpecifier(LFOSpecRec* LFOSpec)
  109.     {
  110.         CheckPtrExistence(LFOSpec);
  111.         DisposeSampleSelectorList(LFOSpec->SampleSources);
  112.         DisposeEnvelope(LFOSpec->WaveTableIndexEnvelope);
  113.         DisposeEnvelope(LFOSpec->FrequencyEnvelope);
  114.         DisposeEnvelope(LFOSpec->AmplitudeEnvelope);
  115.         ReleasePtr((char*)LFOSpec);
  116.     }
  117.  
  118.  
  119. /* get the frequency envelope record */
  120. EnvelopeRec*                    GetLFOSpecFrequencyEnvelope(LFOSpecRec* LFOSpec)
  121.     {
  122.         CheckPtrExistence(LFOSpec);
  123.         return LFOSpec->FrequencyEnvelope;
  124.     }
  125.  
  126.  
  127. /* get the amplitude envelope record */
  128. struct EnvelopeRec*        GetLFOSpecAmplitudeEnvelope(LFOSpecRec* LFOSpec)
  129.     {
  130.         CheckPtrExistence(LFOSpec);
  131.         return LFOSpec->AmplitudeEnvelope;
  132.     }
  133.  
  134.  
  135. /* get the oscillator type for this LFO specifier */
  136. LFOOscTypes                        LFOSpecGetOscillatorType(LFOSpecRec* LFOSpec)
  137.     {
  138.         CheckPtrExistence(LFOSpec);
  139.         return LFOSpec->Oscillator;
  140.     }
  141.  
  142.  
  143. /* change the oscillator type */
  144. void                                    SetLFOSpecOscillatorType(LFOSpecRec* LFOSpec, LFOOscTypes NewType)
  145.     {
  146.         CheckPtrExistence(LFOSpec);
  147.         LFOSpec->Oscillator = NewType;
  148.     }
  149.  
  150.  
  151. /* get the oscillator modulation mode */
  152. LFOModulationTypes        LFOSpecGetModulationMode(LFOSpecRec* LFOSpec)
  153.     {
  154.         CheckPtrExistence(LFOSpec);
  155.         return LFOSpec->ModulationMode;
  156.     }
  157.  
  158.  
  159. /* change the oscillator modulation mode */
  160. void                                    SetLFOSpecModulationMode(LFOSpecRec* LFOSpec,
  161.                                                 LFOModulationTypes NewType)
  162.     {
  163.         CheckPtrExistence(LFOSpec);
  164.         LFOSpec->ModulationMode = NewType;
  165.     }
  166.  
  167.  
  168. /* find out what the adding mode of the LFO is */
  169. LFOAdderMode                    LFOSpecGetAddingMode(LFOSpecRec* LFOSpec)
  170.     {
  171.         CheckPtrExistence(LFOSpec);
  172.         return LFOSpec->AddingMode;
  173.     }
  174.  
  175.  
  176. /* set a new adding mode for the LFO */
  177. void                                    SetLFOSpecAddingMode(LFOSpecRec* LFOSpec,
  178.                                                 LFOAdderMode NewAddingMode)
  179.     {
  180.         CheckPtrExistence(LFOSpec);
  181.         LFOSpec->AddingMode = NewAddingMode;
  182.     }
  183.  
  184.  
  185. /* for wave table lfo oscillators only */
  186. struct EnvelopeRec*        GetLFOSpecWaveTableIndexEnvelope(LFOSpecRec* LFOSpec)
  187.     {
  188.         CheckPtrExistence(LFOSpec);
  189.         return LFOSpec->WaveTableIndexEnvelope;
  190.     }
  191.  
  192.  
  193. /* get the sample selector list */
  194. struct SampleSelectorRec*    GetLFOSpecSampleSelector(LFOSpecRec* LFOSpec)
  195.     {
  196.         CheckPtrExistence(LFOSpec);
  197.         return LFOSpec->SampleSources;
  198.     }
  199.